<?php
namespace Admin\Controller;
use Think\Controller;
class ShufflingController extends CommonController {




    //分类列表页面
    public function index(){
    	//获取数据库
    	$Shuffling = M('mvp_shuffling');
    	//获取数据
    	$info = $Shuffling->join()->select();
        //echo $admin->_sql();die;
    	$this->assign('info',$info);
    	// var_dump($info);die;
    	$this->display();
    }

    public function edit(){
    	//获取要修改的id
    	$id = I('get.id');
    	// echo $id;
    	//查询数据
    	$Shuffling = M('mvp_shuffling');
    	$info = $Shuffling->join()->select();
    	// var_dump($info);
    	// 分配
    	$this->assign('info',$info);
    	//展示要修改的类
    	$this->display();
    }

    public function update(){
    	// var_dump($_POST);
    	//查询数据
    	$Shuffling = M('mvp_shuffling');
        //判断图片路径
        if($_FILES['pic']['error'] == 0){
            $upload = new \Think\Upload();// 实例化上传类    
            $upload->maxSize   =     3145728 ;// 设置附件上传大小    
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型    
            $upload->rootPath = './Public';//手动设置文件上传根目录
            $upload->savePath  =      '/Uploads/Admin/Shuffling/'; // 设置附件上传目录    // 上传文件     
            $infos = $upload->upload(); //var_dump($_POST);   
            if(!$infos) {// 上传错误提示错误信息        
                $this->error($upload->getError(),'',1000000);
            }else{// 上传成功        
                $_POST['pic'] = ltrim($upload->rootPath,'.').$infos['pic']['savepath'].$infos['pic']['savename'];
            }
        }
        
        //创建数据
        $Shuffling->create();
        //执行修改
        $res = $Shuffling->save();
        //echo $User->_sql();

        
    	if($res == 1){
    		$this->success('修改成功',U('Admin/Shuffling/index'),3);
    	}else{
    		$this->error('修改失败',U('Admin/Shuffling/index'),3);

    	}
    }





}